package com.ujiuye.service;

import com.ujiuye.dao.StudentDao;
import com.ujiuye.pojo.Student;
import com.ujiuye.utils.PageTools;

import java.util.List;

public class StudentService {

    private StudentDao studentDao = new StudentDao();
    /**
     * 分页查询
     * @param currentPage
     * @param pageSize
     * @param search
     */
    public PageTools dimQuery(String currentPage, String pageSize, String search) {
        //处理参数
        int cp = 1;
        if(currentPage != null && !"".equals(currentPage)) {
            cp = Integer.parseInt(currentPage);
        }

        int ps = 5;
        if(pageSize != null && !"".equals(pageSize)) {
            ps = Integer.parseInt(pageSize);
        }

        //查询总条数    select count(*) from student where  sname like '%search%'
        int sumSize = studentDao.queryAllSizeBySearch(search);

        //创建工具类对象
        PageTools pt = new PageTools(cp,ps,sumSize);

        //通过工具类和条件去查询数据
        List<Student> lists = studentDao.dimQuery(pt,search);

        pt.setStudentList(lists);
        //把pt返回给servlet
        return pt;




    }
}
